import 'package:flutter/material.dart';
import 'package:untitled/pages/Getx_project/ShopClassBean.dart';
import 'package:untitled/pages/Getx_project/ShopController.dart';
import 'package:untitled/pages/Getx_project/ShopItemWidget.dart';
import 'package:get/get.dart';

class ShopItemPage extends StatefulWidget {
  final ShopClassBean element;
  ShopItemPage(this.element);
  //const ShopItemPage(ShopClassBean element, {Key? key}) : super(key: key);

  @override
  State<ShopItemPage> createState() => _ShopItemPageState();
}
// 商品列表
class _ShopItemPageState extends State<ShopItemPage> {

  ShopController _shopController = Get.put(ShopController());

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // 请求商品列表数据 
    _shopController.requestShopGoodsList(widget.element);
  }
  @override
  Widget build(BuildContext context) {
    return GetBuilder(
      id: "${widget.element.id}",
      builder: (ShopController controller){
      List<GoodsBean> list = controller.currentGoods;
      return ListView.builder(
      itemCount: list.length,
      itemBuilder: (BuildContext context,int index){
        GoodsBean goodsBean = list[index];
        // 获取商品
        return ShopItemWidget(goodsBean);
    });
  });
    
  }
}